<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业名称" prop="gfEpName">
        <el-input
          v-model="queryParams.gfEpName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人" prop="gfPerson">
        <el-input
          v-model="queryParams.gfPerson"
          placeholder="请输入法人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="gfPhone">
        <el-input
          v-model="queryParams.gfPhone"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="gfAddr">
        <el-input
          v-model="queryParams.gfAddr"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="gfIdCard">
        <el-input
          v-model="queryParams.gfIdCard"
          placeholder="请输入身份证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经营许可证" prop="gfJyxkz">
        <el-input
          v-model="queryParams.gfJyxkz"
          placeholder="请输入经营许可证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="暂存库经度" prop="gfZckLg">
        <el-input
          v-model="queryParams.gfZckLg"
          placeholder="请输入暂存库经度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="暂存库纬度" prop="gfZckLt">
        <el-input
          v-model="queryParams.gfZckLt"
          placeholder="请输入暂存库纬度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处置线末端经度" prop="gfCzxLg">
        <el-input
          v-model="queryParams.gfCzxLg"
          placeholder="请输入处置线末端经度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处置线末端纬度" prop="gfCzxLt">
        <el-input
          v-model="queryParams.gfCzxLt"
          placeholder="请输入处置线末端纬度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['solidDispose:gfEp:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['solidDispose:gfEp:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['solidDispose:gfEp:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['solidDispose:gfEp:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="gfEpList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="固废处置企业ID" align="center" prop="gfId" />-->
      <el-table-column label="固废企业名称" align="center" prop="gfEpName" />
      <el-table-column label="法人" align="center" prop="gfPerson" />
      <el-table-column label="联系电话" align="center" prop="gfPhone" />
      <el-table-column label="地址" align="center" prop="gfAddr" />
      <el-table-column label="身份证" align="center" prop="gfIdCard" />
      <el-table-column label="经营许可证" align="center" prop="gfJyxkz" />
      <el-table-column label="暂存库经度" align="center" prop="gfZckLg" />
      <el-table-column label="暂存库纬度" align="center" prop="gfZckLt" />
<!--      <el-table-column label="处置线末端经度" align="center" prop="gfCzxLg" />-->
<!--      <el-table-column label="处置线末端纬度" align="center" prop="gfCzxLt" />-->
<!--      <el-table-column label="备注" align="center" prop="remark" />-->
<!--      <el-table-column label="冗余字段" align="center" prop="other" />-->
<!--      <el-table-column label="冗余字段" align="center" prop="otherOne" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['solidDispose:gfEp:edit']"
          >修改</el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.row)"
            v-hasPermi="['solidDispose:gfEp:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改固废处置企业对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" class="clearfix " label-width="140px">
        <el-form-item label="企业名称" prop="gfEpName">
          <el-input v-model="form.gfEpName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="法人" prop="gfPerson">
          <el-input v-model="form.gfPerson" placeholder="请输入法人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="gfPhone">
          <el-input v-model="form.gfPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="地址" prop="gfAddr">
          <el-input v-model="form.gfAddr" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="身份证" prop="gfIdCard">
          <el-input v-model="form.gfIdCard" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="经营许可证" prop="gfJyxkz">
          <el-input v-model="form.gfJyxkz" placeholder="请输入经营许可证" />
        </el-form-item>
        <el-form-item label="暂存库经度" prop="gfZckLg">
          <el-input v-model="form.gfZckLg" placeholder="请输入暂存库经度" />
        </el-form-item>
        <el-form-item label="暂存库纬度" prop="gfZckLt">
          <el-input v-model="form.gfZckLt" placeholder="请输入暂存库纬度" />
        </el-form-item>
        <el-form-item label="处置线末端经度" prop="gfCzxLg">
          <el-input v-model="form.gfCzxLg" placeholder="请输入处置线末端经度" />
        </el-form-item>
        <el-form-item label="处置线末端纬度" prop="gfCzxLt">
          <el-input v-model="form.gfCzxLt" placeholder="请输入处置线末端纬度" />
        </el-form-item>
<!--        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="冗余字段" prop="other">
          <el-input v-model="form.other" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="冗余字段" prop="otherOne">
          <el-input v-model="form.otherOne" type="textarea" placeholder="请输入内容" />
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center;">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGfEp, getGfEp, delGfEp, addGfEp, updateGfEp, exportGfEp } from "@/api/solidDispose/gfEp";
import {isIntegerNotMust,validatePhoneTwo,validateIdNo,validateEMail} from "@/api/validate/validate";

export default {
  name: "GfEp",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 固废处置企业表格数据
      gfEpList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gfEpName: null,
        gfPerson: null,
        gfPhone: null,
        gfAddr: null,
        gfIdCard: null,
        gfJyxkz: null,
        gfZckLg: null,
        gfZckLt: null,
        gfCzxLg: null,
        gfCzxLt: null,
        other: null,
        otherOne: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        gfEpName: [
          {required: true, message: "企业名称不能为空", trigger: "blur"}
        ],
        gfPerson: [
          {required: true, message: "法人名称不能为空", trigger: "blur"}
        ],
        gfPhone: [
          {required: true,validator:validatePhoneTwo, trigger: "blur"}
        ],
        gfIdCard: [
          {required: true,validator:validateIdNo,trigger: "blur"}
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询固废处置企业列表 */
    getList() {
      this.loading = true;
      listGfEp(this.queryParams).then(response => {
        this.gfEpList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        gfId: null,
        gfEpName: null,
        gfPerson: null,
        gfPhone: null,
        gfAddr: null,
        gfIdCard: null,
        gfJyxkz: null,
        gfZckLg: null,
        gfZckLt: null,
        gfCzxLg: null,
        gfCzxLt: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        other: null,
        otherOne: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.gfId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加固废处置企业";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const gfId = row.gfId || this.ids
      getGfEp(gfId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改固废处置企业";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.gfId != null) {
            updateGfEp(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGfEp(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const gfIds = row.gfId || this.ids;
      this.$confirm('是否确认删除固废处置企业编号为"' + gfIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delGfEp(gfIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有固废处置企业数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportGfEp(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
